'use strict';

/**
 * @ngdoc function
 * @name webApp.controller:TeamCtrl
 * @description
 * # TeamCtrl
 * Controller of the webApp
 */

angular.module('webApp')
  .controller('team', function ($scope,promiseTeam,$ionicScrollDelegate) {
  $scope.slide = true;
  //获取团队数据
  var teamData = function(page){
    $scope.slide = false;
    promiseTeam.teams(page,10).then(function(data){
      var teams = data;
      var len = teams.length;
      for(var i = 0;i < len;i++){
        teams[i].slide = false;
      }
      if($scope.teams){
        $scope.teams = $scope.teams.concat(teams);
      }
      else{
        $scope.teams = teams;
      }
      //下拉事件
      $scope.slideDown = function(event,index){
        if($scope.teams[index].description && $scope.teams[index].description != ''){
          $scope.teams[index].slide = !$scope.teams[index].slide;
          if(!angular.element(event.target).hasClass('slideDown')){
            angular.element(event.target).addClass('slideDown');
          }
          else{
            angular.element(event.target).removeClass('slideDown');
          }
        }
      };
      if(teams.length != 0){
        $scope.slide = true;
      }
      else{
        $scope.slide = false;
      }
    });
  };
  //默认第一页
  var page = 1;
  teamData(page);
  $scope.loadMore = function(){
    page += 1;
    teamData(page);
    $ionicScrollDelegate.resize();
  };
});
